//
//  LBWebViewController.h
//  
//
//  Created by LINAICAI on 2018/1/12.
//  Copyright © 2018年 李柰财. All rights reserved.
//

#import <LBUIKit/LBBaseViewController.h>
#import <WebKit/WebKit.h>
@class WKWebView,WKScriptMessage,JavaScriptAction;

typedef void (^Handler)(WKScriptMessage *);
@interface LBWebViewController : LBBaseViewController
@property (nonatomic , readonly,  copy)NSString *html;
@property (nonatomic , readonly , copy)NSString *url;
@property (nonatomic , readonly , copy)NSString *token;
@property (nonatomic , readonly , strong)WKWebView *webView;
@property (nonatomic , readonly , strong)NSMutableArray<JavaScriptAction *> *methods;


///单独加载html内容
- (instancetype)initWithHtml:(NSString *)html;
///单独加载html内容并设置标题
- (instancetype)initWithHtml:(NSString *)html title:(NSString *)title;

///主要用于JS交互的
- (instancetype)initUrl:(NSString *)url token:(NSString *)token;
///主要用于非JS交互的
- (instancetype)initTitle:(NSString *)title url:(NSString *)url;


///全参数构造方法
- (instancetype)initTitle:(NSString *)title url:(NSString *)url token:(NSString *)token NS_DESIGNATED_INITIALIZER;



///禁止以下初始化方法
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

///OC调JS
- (void)evaluateJavaScript:(NSString *)javaScriptString;
///JS调OC(添加注册Action)
- (void)addAction:(JavaScriptAction *)action;
@end

///JS交互动作封装
@interface JavaScriptAction:NSObject
@property (nonatomic , readonly , strong)NSString *name;
@property (nonatomic , readonly , copy)Handler handler;
+ (instancetype)actionWithName:(NSString *)name handler:(Handler)handler;
@end

///解决无法释放问题
@interface WeakScriptMessageDelegate:NSObject<WKScriptMessageHandler>
@property (nonatomic , weak)id<WKScriptMessageHandler> scriptDelegate;

- (instancetype)initWithDelegate:(id<WKScriptMessageHandler>)scriptDelegate;
@end

